package net.lab1024.sa.base.module.support.syslog.service;

import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

import net.lab1024.sa.base.common.util.SmartRequestUtil;
import net.lab1024.sa.base.module.support.syslog.dao.SyslogConfigDao;
import net.lab1024.sa.base.module.support.syslog.domain.entity.SyslogConfigEntity;
import net.lab1024.sa.base.module.support.syslog.domain.form.SyslogConfigAddForm;
import net.lab1024.sa.base.module.support.syslog.domain.form.SyslogConfigQueryForm;
import net.lab1024.sa.base.module.support.syslog.domain.form.SyslogConfigUpdateForm;
import net.lab1024.sa.base.module.support.syslog.domain.vo.SyslogConfigVO;
import net.lab1024.sa.base.common.util.SmartBeanUtil;
import net.lab1024.sa.base.common.util.SmartPageUtil;
import net.lab1024.sa.base.common.domain.ResponseDTO;
import net.lab1024.sa.base.common.domain.PageResult;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import net.lab1024.sa.base.utils.DateUtilsLocal;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 陈玉强 Service
 *
 * @Author 陈玉强
 * @Date 2025-10-20 00:17:05
 * @Copyright 1
 */

@Service
public class SyslogConfigService {

    @Resource
    private SyslogConfigDao syslogConfigDao;

    /**
     * 分页查询
     */
    public PageResult<SyslogConfigVO> queryPage(SyslogConfigQueryForm queryForm) {
        Page<?> page = SmartPageUtil.convert2PageQuery(queryForm);
        List<SyslogConfigVO> list = syslogConfigDao.queryPage(page, queryForm);
        return SmartPageUtil.convert2PageResult(page, list);
    }

    /**
     * 添加
     */
    public ResponseDTO<String> add(SyslogConfigAddForm addForm) {
        SyslogConfigEntity syslogConfigEntity = SmartBeanUtil.copy(addForm, SyslogConfigEntity.class);
        syslogConfigEntity.setCreateTime(DateUtilsLocal.toLocalDateTime(new Date()));
        syslogConfigEntity.setCreateUser(SmartRequestUtil.getRequestUser().getUserName());
        syslogConfigDao.insert(syslogConfigEntity);
        return ResponseDTO.ok();
    }

    /**
     * 更新
     *
     */
    public ResponseDTO<String> update(SyslogConfigUpdateForm updateForm) {
        SyslogConfigEntity syslogConfigEntity = SmartBeanUtil.copy(updateForm, SyslogConfigEntity.class);
        syslogConfigEntity.setUpdateTime(DateUtilsLocal.toLocalDateTime(new Date()));
        syslogConfigEntity.setUpdateUser(SmartRequestUtil.getRequestUser().getUserName());
        syslogConfigDao.updateById(syslogConfigEntity);
        return ResponseDTO.ok();
    }

    /**
     * 批量删除
     */
    public ResponseDTO<String> batchDelete(List<Integer> idList) {
        if (CollectionUtils.isEmpty(idList)){
            return ResponseDTO.ok();
        }

        syslogConfigDao.deleteBatchIds(idList);
        return ResponseDTO.ok();
    }

    /**
     * 单个删除
     */
    public ResponseDTO<String> delete(Integer id) {
        if (null == id){
            return ResponseDTO.ok();
        }

        syslogConfigDao.deleteById(id);
        return ResponseDTO.ok();
    }
}
